<?php
if(!session_id()) session_start();
header("Expires: Mon, 26 Jul 1970 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-type: text/html; charset=utf-8");

$C_Patch=$_SERVER['DOCUMENT_ROOT'];
include_once($C_Patch."/app/member/utils/login_check.php");
include_once($C_Patch."/app/member/utils/convert_name.php");
include_once("getContentName.php");

$Recpage=20; //每页记录数
$Page=Current_Page($_GET['page']); //获取当前页数
$WhereString="o.user_id=$userid AND o.order_num=o_sub.order_num AND DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= date(o.bet_time) AND o_sub.bet_money>0"; //查询条件
if($_GET['module']=="alreadysettled"){
	$WhereString .= " and o_sub.status in(1,2,3)";
	$PageString="module,alreadysettled"; //页面地址查询条件，格式：字段名称,数据值,字段名称,
}else{
	$WhereString .= " and o_sub.status in(0)";
}

$Field="o.Gtype,o.lottery_number AS qishu,o.rtype_str,o.bet_time,o.order_num,o_sub.quick_type,o_sub.number,o_sub.bet_money AS bet_money_one,o_sub.fs,o.user_id,o_sub.bet_rate AS bet_rate_one,o_sub.is_win,o_sub.status,o_sub.id AS id,o_sub.win AS win_sub,o_sub.balance,o_sub.order_sub_num"; //读取字段
$BaseField="o_sub.id"; //数据表基础字段,默认为ID
$DataTable="order_lottery o,order_lottery_sub o_sub"; //数据表
$SortField="o_sub.id"; //字段排序
$SortType="desc"; //升降排序("Desc"降序,"Asc"为升序)
$CurrentPage=$Page;

$TotalStatistics=Statistics($DataTable,$WhereString); //获取总记录数
$TotalPage=(int)(($TotalStatistics+$Recpage-1)/$Recpage); //获取总页数
if($CurrentPage>$TotalPage&&$TotalPage>0){$TotalStatistics=0;$TotalPage=0;} //清空读取记录集
$query = $mysqli->query(SqlString($Field,$BaseField,$DataTable,$WhereString,$SortField,$SortType,$CurrentPage,$Recpage,$TotalStatistics,$TotalPage)); //获取查询Sql语句
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
    <link rel="stylesheet" href="/Newstyle/lottery/css/content.css">
</head>

<body>
    <div class="tab-wrap">
        <table class="detail-tab">
            <thead>
                <tr>
                    <th>订单号</th>
                    <th>投注时间</th>
                    <th>类型</th>
                    <th>玩法</th>
                    <th>下注金额</th>
                    <th>反水金额</th>
                    <th>可赢金额</th>
                    <th>结算结果</th>
                </tr>
            </thead>
            <?php
			$Total_XZ=0;$Total_FX=0;$Total_WIN=0;$Total_JS=0;
			if($TotalStatistics>0){
				while($rows = $query->fetch_array()){
				$contentName = getName($rows['number'],$rows['Gtype'],$rows['rtype_str'],$rows['quick_type']);
				$money_result = 0;
				if($rows['is_win']=="1"){
					$t_sy= $t_sy + $rows['win_sub'] + $rows['fs'];
					$money_result = $rows['win_sub'] + $rows['fs'];
				}elseif($rows['is_win']=="2"){
					$t_sy+=$rows['bet_money_one'];
					$money_result = $rows['bet_money_one'];
				}elseif($rows['is_win']=="0" && $rows['fs']>0){
					$t_sy+=$rows['fs'];
					$money_result = $rows['fs'];
				}
				$bet_rate = $rows['bet_rate_one'];
				if(strpos($bet_rate,",") !== false){
					$bet_rate_array = explode(",", $bet_rate);
					$bet_rate = $bet_rate_array[0];
				}
				$Total_XZ+=$rows['bet_money_one'];$Total_FX+=$rows['fs'];$Total_WIN+=$rows['win_sub'];$Total_JS+=$money_result;
			?>
            <tbody>
                <tr>
                    <td><?=$rows['order_sub_num']?></td>
                    <td><?=$rows['bet_time']?></td>
                    <td><span class="lottery"><?=getZhPageTitle($rows['Gtype'])?></span><br><span class="draw_number">第 <?=$rows['qishu']?> 期</span></td>
                    <td>
                        <span class="text"><?=$contentName?></span> @ <span class="odds"><?=$bet_rate?></span></td>
                    <td><?=$rows['bet_money_one']?></td>
                    <td><?=$rows['fs']?></td>
                    <td><?=$rows['win_sub']?></td>
                    <?php if($rows['is_win']=="1"){?>
                    <td><span class="odds"><?=$money_result?></span></td>
                    <?php }elseif($rows['status']=="0"){?>
                    <td>-</td>
                    <?php }else{?>
                    <td class="result-color"><?=$money_result?></td>
                    <?php }?>
                </tr>
             <?php }?>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td>总计</td>
                    <th><?=sprintf("%.2f",$Total_XZ)?></th>
                    <td><?=sprintf("%.2f",$Total_FX)?></td>                    
                    <td><?=sprintf("%.2f",$Total_WIN)?></td>
                    <td>
                    <span class="odds"><?=sprintf("%.2f",$Total_JS)?><span class="odds">
                    </td>
                </tr>
                <tr>
                  <td colspan="8" align="center" style="background-color:#FFFFFF;"><?=PageShow($CurrentPage,$TotalPage,$Recpage,$TotalStatistics,$PageString)?></td>
                </tr>
              <?php }else{?>
                <tr>
                  <td colspan="8" align="center">很抱歉，没有符合您要求的记录。</td>
                </tr> 
               <?php }?>           
        </table>
    </div>
</body>
</html>